package models

import (
	"gitee.com/tangrx/go-admin/utils"
	"log"
)

func GetLogList4Pager(form SearchForm) *PageResult {
	sqlWhere := " 1=1 "
	key := form.GetStr("key")
	params := make([]interface{}, 0)
	i := 1
	if len(key) > 0 {
		params = append(params, "%"+form.GetStr("key")+"%")
		sqlWhere += " and (operation like $" + utils.IntToStr(i) + " or method like $" + utils.IntToStr(i) +
			" or opt_params like $" + utils.IntToStr(i) + ")"
		i++
	}
	//
	//if len(form.GetStr("userStatus")) > 0 {
	//	params = append(params, form.GetInt("userStatus"))
	//	sqlWhere += " and user_status = $" + utils.IntToStr(i)
	//	i++
	//}

	return Page("", "*", "sys_log", sqlWhere, "create_time", form.Page, params...)
}

// 删除日志
func DeleteLog(id int) int64 {
	sqlSave := "delete from sys_log  where id=:id"
	db, _ := OpenDB()
	defer db.Close()
	param := map[string]interface{}{"id": id}
	result, err := db.NamedExec(sqlSave, param)
	if err != nil {
		log.Fatalln(err)
		return 0
	} else {
		i, _ := result.RowsAffected()
		return i
	}
}
